package com.network.util.snmp4j;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.snmp4j.Target;
import org.snmp4j.mp.SnmpConstants;

import com.network.topo.node.AbstractNode;
import com.network.topo.node.Interface;
import com.network.topo.snmp.IfTable;

public class SNMPOperations {
	String ipAddress;

	String community;
	
	int version;
	
	private SnmpGet snmp4j = SnmpGet.getInstance("snmp4j", "properties");
	
	private static final Logger _log = Logger.getLogger(SNMPOperations.class.getName());
	public SNMPOperations(String ipAddr, String comm) {

		ipAddress = ipAddr;

		community = comm;

	}
	
	public IfTable getInterfaces(String sysOid) {

		Vector<Interface> collectors = new Vector<Interface>();

		Interface info = new Interface();

		HashMap<String,HashMap<String,String>> extendedInfo=null;

		Target target = null;
		try
		{
			ArrayList<String> comm = new ArrayList<String>();
			comm.add(community);
			_log.info("AbstractNode [" + community + "] SnmpConstants.version1");
			target = AbstractNode.newTarget(snmp4j, ipAddress, comm, SnmpConstants.version1);

			if (target == null)
			{
				_log.info("AbstractNode [" + community + "] SnmpConstants.version2c");
				target = AbstractNode.newTarget(snmp4j, ipAddress, comm, SnmpConstants.version2c);
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

		IfTable ifTable  = null;
		try {

		
			ifTable = IfTable.getInstance(snmp4j,target);
			
		

		} catch (Exception exception) {
			_log.error("", exception);
		} finally {
			
		}
		return ifTable;
	}

	public final int getVersion() {
		return version;
	}

	public final void setVersion(int version) {
		this.version = version;
	}
}
